package com.ideaplugin.datamanager.common;

import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import com.google.common.collect.Lists;
import com.ideaplugin.datamanager.model.common.UserInfo;
import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.query.QueryCondition;

public class UserInfoHolder {
    //管理员角色id
    public static final Long ADMIN_ROLE_ID = 1L;

    public static QueryCondition adminQueryCondition(QueryColumn queryColumn) {
        final UserInfo userInfo = getUserInfo();
        return queryColumn.in(userInfo.getRoleIds()).when(userInfo.isNotAdmin());
    }

    public static QueryCondition adminQueryCondition(QueryCondition queryCondition) {
        final UserInfo userInfo = getUserInfo();
        return queryCondition.when(userInfo.isNotAdmin());
    }


    public static UserInfo getUserInfo() {

//        todo
        final UserInfo userInfo = new UserInfo();
        userInfo.setUserId(1L);
        userInfo.setRoleIds(Lists.newArrayList(1L));


        return (UserInfo) StpUtil.getSession().get(SaSession.USER);
    }
}
